<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>LoginJsp</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
    <style>
         font{
             color:red;
             font-size:10px;
         }
         #w3,#w2,#w5{
             
             display:none;
        }
   </style>
    
    <script>
 
         var flag=new Array(false,false);
         
         function checkAccountFormat(str){
             var num=0;
             for(var i=0;i<str.length;i++){
                var ch=str.charAt(i); 
                if((ch>='0'&&ch<='9')||(ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
                     num++;
             }
             if(num==str.length)
               return true;
             else
                return false;    
         }
         
         function checkAccount(account){
            flag[0]=false;
            var w3=document.getElementById("w3");
            var w2=document.getElementById("w2");
            w3.style.display="none";
            w2.style.display="none";
              if(account.value=="")
                  w3.style.display="block";
              else  if(!checkAccountFormat(account.value)) 
                  w2.style.display="block";
              else 
                 flag[0]=true;
          }
          
          function checkPasswd(passwd){
             flag[1]=false;
             var w5=document.getElementById("w5");
               w5.style.display="none";
             if(passwd.value=="")
               w5.style.display="block";
              else
                 flag[1]=true;
          }
          
          function remove(){
              var w1=document.getElementById("w1");
              var w4=document.getElementById("w4");
              w1.style.display="none";
              w4.style.display="none";
          }
      
         function login(){
              if(flag[0]==true&&flag[1]==true)
                  return true;
               else{
                  alert("请检查账号信息是否完整，格式是否错误");
                  return false;
               }
         }
    
    </script>
  </head>
  
  <body>
     <h1>登录页面</h1>
     <%
         String name=request.getParameter("name");
         if(name==null)
              name="";
         else{
             byte[] temp=name.getBytes("ISO-8859-1");
             name=new String(temp,"utf-8");
          }
          
       
     
      %>
     <form onclick="remove()" onsubmit="return login()" action="servlet/LoginServlet">
     <table>
        <tbody>
            <tr>
                 <td>账号:</td>
                 <td><input type="text" name="name" onkeyup="checkAccount(this)" value="<%=name %>"/></td>
                 <td>
                     <font id="w1">${requestScope.error==2?"*当前账号不存在":""}</font>
                     <font id="w2">*账号必须由数字和字母组成</font>
                     <font id="w3">*账号不得为空</font>
                 </td>
            </tr>
            <tr>
                 <td>密码:</td>
                 <td><input type="password" name="passwd" onkeyup="checkPasswd(this)" value="${param.passwd}"/></td>
                 <td> 
                     <font id="w4">${requestScope.error==1?"*密码错误":""}</font>
                     <font id="w5">*密码不得为空</font>
                 </td>
            </tr>
            
   
       </tbody>
     </table>
      <input type="submit" value="登陆"/>
      <input type="reset" value="重置"/>
     </form>
    
    <a href="RegisterJsp.jsp">没有账号？请注册</a>
  
   
  </body>
</html>
